#include "Interpolation.h"
#include<fstream>
#include<iostream>

class F1:public Function
{
   public:
           double operator()(const double &x)const
           {
               return 1/(1+pow(x,2));
           }
};

class G1:public Function
{
   private:
           int n;
   public:
           G1(int n):n(n){}
           double operator()(const double &x)const
           {
               return -5+10*x/n;
           }
           double diff(const int &order,const double &x)const
           {
               return 0;
           }
};

int main()
{
     G1 g1(2),g2(4),g3(6),g4(8);
     F1 f;
     double non;
     double out1[23];
     double out2[23];
     Subroutine Sub1(f,g1,2),Sub2(f,g2,4),Sub3(f,g3,6),Sub4(f,g4,8);
     Sub1.generate();
     Sub2.generate();
     Sub3.generate();
     Sub4.generate();
     non=Sub1.Newtvalue(1);
     non=Sub2.Newtvalue(1);
     non=Sub3.Newtvalue(1);
     non=Sub4.Newtvalue(1);

     for(int i=0;i<=2;i++)
     {
         cout<<g1(double(i))<<"  "<<Sub1.c[i]<<" "<<endl;
         out1[i]=Sub1.c[i];
         out2[i]=g1(double(i));
     }  
     cout<<endl;
     for(int i=0;i<=4;i++)
     {
         cout<<g2(double(i))<<"  "<<Sub2.c[i]<<" "<<endl;
         out1[i+3]=Sub2.c[i];
         out2[i+3]=g2(double(i));
     }  
     cout<<endl;
     for(int i=0;i<=6;i++)
     {
         cout<<g3(double(i))<<"  "<<Sub3.c[i]<<" "<<endl;
         out1[i+8]=Sub3.c[i];
         out2[i+8]=g3(double(i));
     }  
     cout<<endl;
     for(int i=0;i<=8;i++)
     {
         cout<<g4(double(i))<<"  "<<Sub4.c[i]<<" "<<endl;
         out1[i+15]=Sub4.c[i];
         out2[i+15]=g4(double(i));
     }  
     
     ofstream datafile;
     datafile.open("1.txt",ofstream::app);
     for(int i=0;i<=23;i++)
     {
         datafile<<out1[i]<<" "<<out2[i]<<endl;
     }
     datafile.close();
 
     return 0;
}
